{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"color:#777777;background-color:#ffffff;font-size:12px;text-align:right;\">\n",
    "\tprepared by Abuzer Yakaryilmaz (QuSoft@Riga) | November 07, 2018\n",
    "</div>\n",
    "<table><tr><td><i> I have some macros here. If there is a problem with displaying mathematical formulas, please run me to load these macros.</i></td></td></table>\n",
    "$ \\newcommand{\\bra}[1]{\\langle #1|} $\n",
    "$ \\newcommand{\\ket}[1]{|#1\\rangle} $\n",
    "$ \\newcommand{\\braket}[2]{\\langle #1|#2\\rangle} $\n",
    "$ \\newcommand{\\inner}[2]{\\langle #1,#2\\rangle} $\n",
    "$ \\newcommand{\\biginner}[2]{\\left\\langle #1,#2\\right\\rangle} $\n",
    "$ \\newcommand{\\mymatrix}[2]{\\left( \\begin{array}{#1} #2\\end{array} \\right)} $\n",
    "$ \\newcommand{\\myvector}[1]{\\mymatrix{c}{#1}} $\n",
    "$ \\newcommand{\\myrvector}[1]{\\mymatrix{r}{#1}} $\n",
    "$ \\newcommand{\\mypar}[1]{\\left( #1 \\right)} $\n",
    "$ \\newcommand{\\mybigpar}[1]{ \\Big( #1 \\Big)} $\n",
    "$ \\newcommand{\\sqrttwo}{\\frac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\dsqrttwo}{\\dfrac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\onehalf}{\\frac{1}{2}} $\n",
    "$ \\newcommand{\\donehalf}{\\dfrac{1}{2}} $\n",
    "$ \\newcommand{\\hadamard}{ \\mymatrix{rr}{ \\sqrttwo & \\sqrttwo \\\\ \\sqrttwo & -\\sqrttwo }} $\n",
    "$ \\newcommand{\\vzero}{\\myvector{1\\\\0}} $\n",
    "$ \\newcommand{\\vone}{\\myvector{0\\\\1}} $\n",
    "$ \\newcommand{\\vhadamardzero}{\\myvector{ \\sqrttwo \\\\  \\sqrttwo } } $\n",
    "$ \\newcommand{\\vhadamardone}{ \\myrvector{ \\sqrttwo \\\\ -\\sqrttwo } } $\n",
    "$ \\newcommand{\\myarray}[2]{ \\begin{array}{#1}#2\\end{array}} $\n",
    "$ \\newcommand{\\X}{ \\mymatrix{cc}{0 & 1 \\\\ 1 & 0}  } $\n",
    "$ \\newcommand{\\Z}{ \\mymatrix{rr}{1 & 0 \\\\ 0 & -1}  } $\n",
    "$ \\newcommand{\\Htwo}{ \\mymatrix{rrrr}{ \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} } } $\n",
    "$ \\newcommand{\\CNOT}{ \\mymatrix{cccc}{1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0} } $\n",
    "$ \\newcommand{\\norm}[1]{ \\left\\lVert #1 \\right\\rVert } $"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2>One Qubit</h2>\n",
    "\n",
    "A qubit (quantum bit) has two states: state 0 and state 1.\n",
    "\n",
    "They are denoted by ket-notation:\n",
    "\n",
    "$ \\ket{0} $ and $ \\ket{1} $.\n",
    "\n",
    "We can show them as vectors:\n",
    "\n",
    "$ \\ket{0} = \\myvector{1 \\\\ 0} $ and $ \\ket{1} = \\myvector{0\\\\ 1} $."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> NOT operator </h3>\n",
    "\n",
    "NOT operator flips the value of a qubit.\n",
    "\n",
    "We use capital letter for the matrix form of the operators:\n",
    "\n",
    "$ X = \\X$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"background-color:#f8f8f8;color:#555555;font-size:13px;\">\n",
    "<b><i>A technical note: Why is NOT operator referred as x-gate?<i></b>\n",
    "   \n",
    "In Bronze, we use only real numbers, but we should note that complex numbers are also used in quantum computing. \n",
    "    \n",
    "When complex numbers are used, a qubit can be represented by a four dimensional real number valued vector, which is not possible to visualize.\n",
    "\n",
    "On the other hand, it is still possible to represent a qubit (with complex numbers) equivalently in three dimensions. \n",
    "\n",
    "This representation is called Bloch sphere. \n",
    "\n",
    "In three dimentions, we have axis: x, y, and z. \n",
    "\n",
    "X refers to the rotation with respect to x-axis.\n",
    "\n",
    "Similarly, we have the rotation with respect to y-axis and z-axis.\n",
    "\n",
    "In Bronze, we will also see the operator Z (z-gate).\n",
    "\n",
    "The operator Y is defined with complex numbers.\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The action of $ X $ on the qubit:\n",
    "\n",
    "$ X \\ket{0} = \\ket{1} $. \n",
    "\n",
    "More explicitly, $ X \\ket{0} = \\X \\vzero = \\vone = \\ket{1} $.\n",
    "\n",
    "Similarly, $ X \\ket{1} = \\ket{0} $.\n",
    "\n",
    "More explicitly, $ X \\ket{1} = \\X \\vone = \\vzero = \\ket{0} $."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Hadamard operator</h3>\n",
    "\n",
    "Hadamard operator ($ H $ or h-gate) looks like a fair coin-flipping.\n",
    "\n",
    "$$\n",
    "    H = \\hadamard.\n",
    "$$\n",
    "\n",
    "But, there are certain dissimilarities:\n",
    "<ul>\n",
    "    <li> we have a <u>negative entry</u>, and</li>\n",
    "    <li> instead of $ \\frac{1}{2} $, we have <u>its square root</u> $ \\mypar{ \\frac{1}{\\sqrt{2}} } $. </li>\n",
    "</ul>\n",
    "\n",
    "<font color=\"blue\"><b> Quantum systems can have negative transitions.</b></font>\n",
    "\n",
    "<font color=\"red\"> Probabilistic system with negative values. How can this be possible? </font> "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> One-step Hadamard</h4>\n",
    "\n",
    "Let's start in $ \\ket{0} $.\n",
    "\n",
    "After applying $ H $:\n",
    "\n",
    "$$\n",
    "    \\vhadamardzero = \\hadamard \\vzero = H \\ket{0}.\n",
    "$$\n",
    "\n",
    "After measurement, we observe the zero and one states with equal probability $ \\frac{1}{2} $. \n",
    "\n",
    "How can this be possible when their values are $ \\frac{1}{\\sqrt{2}} $?\n",
    "\n",
    "<img src=\"../images/photon3a.jpg\" width=\"45%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's start in $ \\ket{1} $.\n",
    "\n",
    "After applying $ H $:\n",
    "\n",
    "$$\n",
    "    \\vhadamardone = \\hadamard \\vone = H \\ket{1}.\n",
    "$$\n",
    "\n",
    "After measurement, we observe the zero and one states with equal probability $ \\frac{1}{2} $. \n",
    "\n",
    "We obtain the same values even when one of the value is negative. \n",
    "\n",
    "<img src=\"../images/photon3b.jpg\" width=\"35%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<i>The absolute value of a negative value is positive.</i>\n",
    "\n",
    "<i>The square of a negative value is also positive.</i>\n",
    "\n",
    "As we have observed, the second fact would help to read the measurement results.\n",
    "\n",
    "<font color=\"blue\"><b> When a quantum system is measured, the probability of observing one state is the sqaure of its value.</b></font>\n",
    "\n",
    "In order to distinguish the value of a state to be in from the probability of a state to be observed, the value of a state to be in is called its <b>amplitude</b>.\n",
    "\n",
    "In the above example, the amplitude of the zero and one states are respectively $ \\sqrttwo $ and $ -\\sqrttwo $.\n",
    "\n",
    "Their probabilities to be observed after measurement are $ \\onehalf $."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Task 1 </h3>\n",
    "\n",
    "What are the probabilities of observing the states  $ \\ket{0} $ and $ \\ket{1} $ if our system is in $ \\myvector{-\\frac{3}{5} \\\\ - \\frac{4}{5}} $ or $ \\myvector{\\frac{3}{5} \\\\ \\frac{4}{5}} $ or $ \\myrvector{\\frac{1}{\\sqrt{3}} \\\\ - \\frac{\\sqrt{2}}{\\sqrt{3}}} $?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    "# you may use python  \n",
    "#\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Quantum state </h3>\n",
    "\n",
    "<i>What do we know at this point?</i>\n",
    "<ul>\n",
    "    <li> A quantum state can be represented by a vector, in which each entry can be zero, a positive value, or a negative value. </li>\n",
    "    <li> We can also say that the amplitude of any state can be zero, a positive value, or a negative value. </li>\n",
    "    <li> The probability of observing one state after measurement is the square of its amplitude. </li>\n",
    "</ul>\n",
    "\n",
    "<i>What else can we say?</i>\n",
    "\n",
    "Can the entries of a quantum state be arbitrary?\n",
    "\n",
    "Do you remember the properties of a probabilistic state?"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
